﻿@model Telecom.Data.LAP_THIETBI

@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequestDauNoiTB"
    };
}

<script type="text/javascript">

    function opBeginProcess_loading_window_submit_Daunoi_lap_dat() {

        $("#ContentwindowFunction_daunoi_laptb").mask("Dữ liệu đang xử lý");


    }

    function completedAjaxRequestDauNoiTB(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        if (returnObj.Status == "success") {


            $("#ChoosePortvalue_pgaelapdat").val($("#ChoosePortvalue").val());
            $("#ChooseTBDauVaovalue_pgaelapdat").val($("#ChooseTBDauVaovalue").val());
            $("#ChooseCardauVaovalue_pgaelapdat").val($("#ChooseCardauVaovalue").val());
            $("#ChooseMaTBDauVaovalue_pgaelapdat").val($("#ChooseMaTBDauVaovalue").val());
            $("#ChooseSlotCardauVaovalue_pgaelapdat").val($("#ChooseSlotCardauVaovalue").val());

            var MaTbvalueFormDauNoi =  $("#ChooseMaTBDauVaovalue").val();

            var stringPortSo = "";
            var matbCutString = "";
            var stringSlot = "";

            if (MaTbvalueFormDauNoi != "" && MaTbvalueFormDauNoi != null) {
                try {

                    matbCutString = MaTbvalueFormDauNoi.split('-')[1];
                }
                catch (e) {
                    matbCutString = "";
                }
            }

            


            if ($("#ChoosePortvalue").val() != "" && $("#ChoosePortvalue").val() != null) {

                stringPortSo = Get_Port_ById($("#ChoosePortvalue").val()).PORT_SO;

            }

            var stringMaDauNoi = "";

            if (MaTbvalueFormDauNoi.indexOf("OLT") != -1) {

                stringSlot = $("#ChooseSlotCardauVaovalue").val();

                stringMaDauNoi = $("#MaTBChosse_lapTb").val() + "-" + matbCutString + "." + $("#ChooseSlotCardauVaovalue").val() + "." + stringPortSo + "." + stringPortSo;

            }
            else {

                stringMaDauNoi = $("#MaTBChosse_lapTb").val() + "-" + matbCutString + "." + stringPortSo;

            }

            

            $("#MA_LAP_TB").val(stringMaDauNoi);
            //$("#TEN_LAP_TB").val(stringMaDauNoi);

            close_window_elements('window_addupdate_dau_noi_thietbi_lap_dat');


        } else {

            $("#ContentwindowFunction_daunoi_laptb").unmask();
            confirmOptionNormal(returnObj.Message);
        }

        return false;

    }

    $(document).ready(function () {

        $("#CAUHINHTB_ON_DAU_NOI").combogrid({

            url: _nameSubDomain + "/TThietbi/List_Cau_Hinh_Tb_Dau_Noi?Id=0&toql=@ViewBag.ToqlDauNoiTB&tramvt=@ViewBag.TRAMVT_DNTB_LAPTB",
            idField: 'ID',
            textField: 'TEN',
            fitcomlumm: true,
            //value : $("#ChooseTBDauVaovalue_pgaelapdat").val(),
            columns: [[
                { field: 'MA', title: 'Mã CHTB', width: 120 },
                { field: 'TEN', title: 'Tên CHTB', width: 170 },
                {
                    field: 'SITEID', title: ' SITE', width: 140, formatter: function (value, row, index) {
                        if (value != null) {
                            return Get_vnpt_site_ById(value).TEN;
                        }
                        else return "";
                    }
                },
            ]],
            onSelect: function (index, row) {

                $("#ChooseTBDauVaovalue").val(row.ID);
                $("#ChooseMaTBDauVaovalue").val(row.MA);

                $.ajax({ url: _nameSubDomain + '/TThietbi/FindFistCauHinhTBJSon?lapTBId=' + row.ID, async: false }).done(function (data) {

                    $("#CARD_ON_DAU_NOI").combogrid({ url: _nameSubDomain + '/TThietbi/ListCauHinhTBJSon?lapTBId=' + row.ID });
                    
                        $("#CARD_ON_DAU_NOI").combogrid('setValue', data.ID);

                        $("#ChooseCardauVaovalue").val(data.ID);
                        $("#ChooseSlotCardauVaovalue").val(data.SLOT);

                        $(".porton_Cart").html("");

                        $(".porton_Cart").mask("Đang load Port ...");

                        $(".porton_Cart").html(ListPortByCauHinh(data.ID));

                        SetCheckboxListSingle("cblFaxTypes", "ChoosePortvalue");

                        setTimeout(function () { $(".porton_Cart").unmask(); }, 200);



                });

                

            }
        });


        $("#CARD_ON_DAU_NOI").combogrid({

            //url: _nameSubDomain + '/TThietbi/ListCauHinhTBJSon?lapTBId=' + $("#ChooseTBDauVaovalue_pgaelapdat").val(),
            idField: 'ID',
            textField: 'TEN',
            fitcomlumm: true,
            //value: $("#ChooseCardauVaovalue_pgaelapdat").val(),
            columns: [[
                //{ field: 'MA', title: 'Mã CARD', width: 100 },
                { field: 'TEN', title: 'Tên CH Card', width: 160 },
                {
                    field: 'CARD', title: 'Card', width: 220, formatter: function (value, row, index) {
                        if (value != null) {
                            return Get_Card_ById(value).TEN;
                        }
                        else return "";

                    }
                },
                {
                    field: 'SLOT', title: ' SLOT'
                },
            ]],
            onSelect: function (index, row) {

                $("#ChooseCardauVaovalue").val(row.ID);
                $("#ChooseSlotCardauVaovalue").val(row.SLOT);

                $(".porton_Cart").html("");

                $(".porton_Cart").mask("Đang load Port ...");

                $(".porton_Cart").html(ListPortByCauHinh(row.ID));

                SetCheckboxListSingle("cblFaxTypes", "ChoosePortvalue");

                setTimeout(function () { $(".porton_Cart").unmask(); }, 200);

            },
            onLoadSuccess: function (obj) {

                //$(".porton_Cart").html(ListPortByCauHinh($("#ChooseCardauVaovalue_pgaelapdat").val()));
                //SetCheckboxListSingle("cblFaxTypes", "ChoosePortvalue");

            }

        });



    });

    function ListPortByCauHinh(id) {



            var StrChuoiPort = "<div id='cblFaxTypes'> <ul class='listPort'>";

            $.ajax({ url: _nameSubDomain + "/TThietbi/ListPortByCauHinhJson_lap_dat?cauhinh=" + id, async: false }).done(function (data) {

                for (var i = 0; i < data.length; i++) {

                    if (data[i].TRANGTHAI == 2) {

                        StrChuoiPort += "<li>"
                                    + "<input type='checkbox' id='" + data[i].ID + "' checked disabled='disabled' value='" + data[i].ID + "'>"
                                    + " <span>&nbsp;&nbsp;Port: " + data[i].PORT_SO + "</span> "
                                    + "</li>";

                    }
                    else {

                        StrChuoiPort += "<li>"
                                    + "<input class='inputcheckPortDauNoi' type='checkbox' id='" + data[i].ID + "' value='" + data[i].ID + "'>"
                                    + " <span>&nbsp;&nbsp;Port: " + data[i].PORT_SO + "</span> "
                                    + "</li>";

                    }
                }


            });

            StrChuoiPort += "</ul></div>";



            return StrChuoiPort;

        }

</script>

@using (Ajax.BeginForm("DauNoiTB_LAPTb", "TThietbi", null, ajaxOpts, new { enctype = "multipart/form-data" }))
{
    
    <input type="hidden" id="ChoosePortvalue" name="ChoosePortvalue" value="" />
    <input type="hidden" id="ChooseMaTBDauVaovalue" name="ChooseMaTBDauVaovalue" value="" />
    
    <input type="hidden" id="ChooseTBDauVaovalue" name="ChooseTBDauVaovalue" value="" />
    <input type="hidden" id="ChooseCardauVaovalue" name="ChooseCardauVaovalue" value="" />
    <input type="hidden" id="ChooseSlotCardauVaovalue" name="ChooseSlotCardauVaovalue" value="" />
    
    <div id="ContentwindowFunction_daunoi_laptb" class="ContentwindowFunction_daunoi_laptb">
       <table class="tableContentWindowFunction">
           
           <tr>
                <td>
                   Thiết bị : 
                </td>
               <td>
                    <input class="easyui-combogrid" value="" style="width:450px; height:27px" id="CAUHINHTB_ON_DAU_NOI" name="CAUHINHTB_ON_DAU_NOI">
               </td>
           </tr>
           <tr>
                <td>
                    Card  : 
                </td>
               <td>
                   <input class="easyui-combogrid" value="" style="width:450px; height:27px" id="CARD_ON_DAU_NOI" name="CARD_ON_DAU_NOI">
               </td>
           </tr>
           <tr>
                <td style="vertical-align:top; padding-top:10px">
                   Port : 
                </td>
               <td>
                    <div class="porton_Cart" style="width:430px; padding:10px; min-height:60px">
                        <p>- Chọn Card để hiển thị PORT</p>
                    </div>
               </td>
           </tr>
           


       </table>
        <div style="height:30px"></div>
        <div class="footer_submit" style="margin-top: 10px; text-align: center">
            <button type="submit" onclick="return opBeginProcess_loading_window_submit_Daunoi_lap_dat(); ">
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Lấy thông tin đấu nối</span><span class="l-btn-icon icon-add">&nbsp;</span></span>    
            </button>
            <button type="button" onclick="return close_window_elements('window_addupdate_dau_noi_thietbi_lap_dat');" >
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Hủy bỏ</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></button>
        </div>
    </div>
    

}